package com.cxb.manager;

import android.content.Context;
import android.media.AudioManager;
import com.cxb.utils.SharedPreferencesUtils;

/**
 * Created by eric on 2016/6/26.
 */
public class SoundManager {

    public static  void setPhoneMute(boolean enable, Context context) {

        AudioManager audioManager = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
        SharedPreferencesUtils sp = new SharedPreferencesUtils(context);
        if (enable) {
            int volumn = audioManager
                    .getStreamVolume(AudioManager.STREAM_MUSIC);
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
            audioManager
                    .setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
            audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0);
            audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
            audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
            audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            sp.setVoulmn(volumn);

        } else {
            int volumn = sp.getVolumn();
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volumn, 0);
            audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,
                    volumn, 0);
            audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, volumn, 0);
            audioManager.setStreamVolume(AudioManager.STREAM_RING, volumn, 0);
            audioManager.setStreamVolume(AudioManager.STREAM_ALARM, volumn, 0);
            audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
    }
}
